// API配置文件
export const API_CONFIG = {
    // 基础配置
    BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL || '/api',
    TIMEOUT: 30000,

    // 重试配置
    RETRY_ATTEMPTS: 3,
    RETRY_DELAY: 1000,

    // 缓存配置
    CACHE_TTL: 5 * 60 * 1000, // 5分钟

    // 上传配置
    UPLOAD_TIMEOUT: 120000, // 2分钟
    MAX_FILE_SIZE: 100 * 1024 * 1024, // 100MB
    CHUNK_SIZE: 1024 * 1024, // 1MB chunks

    // 分页默认值
    DEFAULT_PAGE_SIZE: 20,
    MAX_PAGE_SIZE: 100,

    // 开发模式配置
    USE_MOCK_API: process.env.NODE_ENV === 'development' &&
        process.env.NEXT_PUBLIC_USE_MOCK_API === 'true',

    // 日志配置
    ENABLE_REQUEST_LOGGING: process.env.NODE_ENV === 'development',
    ENABLE_RESPONSE_LOGGING: process.env.NODE_ENV === 'development',

    // 错误处理配置
    SHOW_ERROR_DETAILS: process.env.NODE_ENV === 'development',

    // 认证配置
    AUTH_TOKEN_KEY: 'auth_token',
    REFRESH_TOKEN_KEY: 'refresh_token',

    // 健康检查配置
    HEALTH_CHECK_INTERVAL: 30000, // 30秒

    // 支持的文件格式
    SUPPORTED_IMAGE_FORMATS: [
        'image/jpeg',
        'image/png',
        'application/dicom',
        'application/x-nifti',
        'application/octet-stream'
    ],

    // MIME类型映射
    MIME_TYPE_EXTENSIONS: {
        'image/jpeg': '.jpg',
        'image/png': '.png',
        'application/dicom': '.dcm',
        'application/x-nifti': '.nii',
        'application/octet-stream': '.bin'
    }
} as const

// 环境特定配置
export const getEnvironmentConfig = () => {
    const env = process.env.NODE_ENV

    switch (env) {
        case 'development':
            return {
                ...API_CONFIG,
                TIMEOUT: 60000, // 开发环境更长的超时时间
                ENABLE_REQUEST_LOGGING: true,
                ENABLE_RESPONSE_LOGGING: true,
                SHOW_ERROR_DETAILS: true
            }

        case 'production':
            return {
                ...API_CONFIG,
                ENABLE_REQUEST_LOGGING: false,
                ENABLE_RESPONSE_LOGGING: false,
                SHOW_ERROR_DETAILS: false
            }

        case 'test':
            return {
                ...API_CONFIG,
                USE_MOCK_API: true,
                TIMEOUT: 5000,
                RETRY_ATTEMPTS: 1
            }

        default:
            return API_CONFIG
    }
}

export default API_CONFIG